package xyz.xiaomuyu.moment_read_app.Fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import java.util.Calendar;

import xyz.xiaomuyu.moment_read_app.R;
import xyz.xiaomuyu.moment_read_app.activity.Homeselect;
import xyz.xiaomuyu.moment_read_app.activity.Music;
import xyz.xiaomuyu.moment_read_app.activity.Read;
import xyz.xiaomuyu.moment_read_app.bean.woshishabi;

public class NotificationFragment extends Fragment {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        //不同的Activity对应不同的布局
        View view = inflater.inflate(R.layout.fragment_notifications, container, false);
        TextView calendartV = (TextView) view.findViewById(R.id.calendar);
        Calendar calendar = Calendar.getInstance();
        String month = "";
        switch(calendar.get(Calendar.MONTH)) {//1月是0
            case 0 : month = "Jan.";break;
            case 1 : month = "Feb.";break;
            case 2 : month = "Mar.";break;
            case 3 : month = "Apr.";break;
            case 4 : month = "May.";break;
            case 5 : month = "Jun.";break;
            case 6 : month = "Jul.";break;
            case 7 : month = "Aug.";break;
            case 8 : month = "Sept.";break;
            case 9 : month = "Oct.";break;
            case 10 : month = "Nov.";break;
            case 11 : month = "Dec.";break;
        }
        String s = "";
        s=calendar.get(Calendar.DAY_OF_MONTH)+" "+month+calendar.get(Calendar.YEAR)+"▼";//设置文本框显示
        calendartV.setText(s);


        calendartV.setOnClickListener(new View.OnClickListener(){
            public void onClick(View view){
                Intent intent=new Intent(getActivity(), Homeselect.class);
                startActivity(intent);
            }
        });

        LinearLayout linearLayoutread=(LinearLayout)view.findViewById(R.id.read);
        linearLayoutread.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getActivity(), Read.class);
                startActivity(intent);
            }
        });

        LinearLayout linearLayoutmusic=(LinearLayout)view.findViewById(R.id.music);
        linearLayoutmusic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getActivity(), Music.class);
                startActivity(intent);
            }
        });
//        从数据库拿照片，设置照片。
//        ImageView imageView111 = (ImageView)view.findViewById(R.id.a111);
//        imageView111.setImageResource(R.drawable.mom);
        ImageView imageViewshoucang=(ImageView)view.findViewById(R.id.shoucang);
        imageViewshoucang.setOnClickListener(new View.OnClickListener() {
            boolean flag = true;
            @Override
            public void onClick(View v) {
                if (flag) {
                    imageViewshoucang.setImageResource(R.drawable.collect2);
                    Toast.makeText(getContext(),"收藏成功",Toast.LENGTH_SHORT).show();
                    woshishabi.collection_sheying1 = 1;
                    flag=false;
                }
                else {
                    imageViewshoucang.setImageResource(R.drawable.collect);
                    Toast.makeText(getContext(),"取消收藏",Toast.LENGTH_SHORT).show();
                    flag=true;
                    woshishabi.collection_sheying1 = 0;
                }
            }
        });

        ImageView imageViewshoucangread=(ImageView)view.findViewById(R.id.shoucangread);
        imageViewshoucangread.setOnClickListener(new View.OnClickListener() {
            boolean flag=true;
            @Override
            public void onClick(View v) {
                if (flag) {
                    imageViewshoucangread.setImageResource(R.drawable.collect2);
                    Toast.makeText(getContext(),"收藏成功",Toast.LENGTH_SHORT).show();
                    woshishabi.collection_read = 1;
                    flag=false;
                }
                else {
                    imageViewshoucangread.setImageResource(R.drawable.collect);
                    Toast.makeText(getContext(),"取消收藏",Toast.LENGTH_SHORT).show();
                    woshishabi.collection_read = 0;
                    flag=true;
                }
            }
        });


        ImageView imageViewshoucangmusic=(ImageView)view.findViewById(R.id.shoucangmusic);
        imageViewshoucangmusic.setOnClickListener(new View.OnClickListener() {
            boolean flag=true;
            @Override
            public void onClick(View v) {
                if (flag) {
                    imageViewshoucangmusic.setImageResource(R.drawable.collect2);
                    Toast.makeText(getContext(),"收藏成功",Toast.LENGTH_SHORT).show();
                    woshishabi.collection_music = 1;
                    flag=false;
                }
                else {
                    imageViewshoucangmusic.setImageResource(R.drawable.collect);
                    Toast.makeText(getContext(),"取消收藏",Toast.LENGTH_SHORT).show();
                    flag=true;
                    woshishabi.collection_music = 0;
                }
            }
        });

        ImageView imageViewdianzan=(ImageView)view.findViewById(R.id.dianzan);
        imageViewdianzan.setOnClickListener(new View.OnClickListener() {
            boolean flag = true;
            @Override
            public void onClick(View v) {
                if (flag) {
                    imageViewdianzan.setImageResource(R.drawable.like2);
                    Toast.makeText(getContext(),"点赞成功",Toast.LENGTH_SHORT).show();
                    flag=false;
                }
                else {
                    imageViewdianzan.setImageResource(R.drawable.like);
                    Toast.makeText(getContext(),"取消点赞",Toast.LENGTH_SHORT).show();
                    flag=true;
                }
            }
        });

        ImageView imageViewdianzanread=(ImageView)view.findViewById(R.id.dianzanread);
        imageViewdianzanread.setOnClickListener(new View.OnClickListener() {
            boolean flag = true;
            @Override
            public void onClick(View v) {
                if (flag) {
                    imageViewdianzanread.setImageResource(R.drawable.like2);
                    Toast.makeText(getContext(),"点赞成功",Toast.LENGTH_SHORT).show();
                    flag=false;
                }
                else {
                    imageViewdianzanread.setImageResource(R.drawable.like);
                    Toast.makeText(getContext(),"取消点赞",Toast.LENGTH_SHORT).show();
                    flag=true;
                }
            }
        });

        ImageView imageViewdianzanyinyue=(ImageView)view.findViewById(R.id.dianzanyinyue);
        imageViewdianzanyinyue.setOnClickListener(new View.OnClickListener() {
            boolean flag = true;
            @Override
            public void onClick(View v) {
                if (flag) {
                    imageViewdianzanyinyue.setImageResource(R.drawable.like2);
                    Toast.makeText(getContext(),"点赞成功",Toast.LENGTH_SHORT).show();
                    flag=false;
                }
                else {
                    imageViewdianzanyinyue.setImageResource(R.drawable.like);
                    Toast.makeText(getContext(),"取消点赞",Toast.LENGTH_SHORT).show();
                    flag=true;
                }
            }
        });

//        ImageView imageViewshoucang1=(ImageView)view.findViewById(R.id.shoucang1);
//        imageViewshoucang1.setOnClickListener(new View.OnClickListener() {
//            boolean flag = true;
//            @Override
//            public void onClick(View v) {
//                if (flag) {
//                    imageViewshoucang1.setImageResource(R.drawable.collect2);
//                    Toast.makeText(getContext(),"收藏成功",Toast.LENGTH_SHORT).show();
//                    woshishabi.collection_sheying1 = 1;
//                    flag=false;
//                }
//                else {
//                    imageViewshoucang1.setImageResource(R.drawable.collect);
//                    Toast.makeText(getContext(),"取消收藏",Toast.LENGTH_SHORT).show();
//                    flag=true;
//                    woshishabi.collection_sheying1 = 0;
//                }
//            }
//        });
//
//        ImageView imageViewdianzan1=(ImageView)view.findViewById(R.id.dianzan1);
//        imageViewdianzan1.setOnClickListener(new View.OnClickListener() {
//            boolean flag = true;
//            @Override
//            public void onClick(View v) {
//                if (flag) {
//                    imageViewdianzan1.setImageResource(R.drawable.like2);
//                    Toast.makeText(getContext(),"点赞成功",Toast.LENGTH_SHORT).show();
//                    flag=false;
//                }
//                else {
//                    imageViewdianzan1.setImageResource(R.drawable.like);
//                    Toast.makeText(getContext(),"取消点赞",Toast.LENGTH_SHORT).show();
//                    flag=true;
//                }
//            }
//        });
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        /**
         * TODO 实现底部菜单对应布局控件事件
         * */

    }
}
